#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main()
{
	int x, y, a, b, where, fire, foeX, foeY, die, score;
	int i, j;
	char input, con;
	i = 0;
	j = 0;
	x = 20;
	y = 10;
	foeX = 19;
	foeY = 9;
	where = 2;
	fire = 0;
	die = 0;
	score = 0;
	START:if (i == 0)
	{
		printf("H");
		Sleep(150);
		printf("e");
		Sleep(150);
		printf("l");
		Sleep(150);
		printf("l");
		Sleep(150);
		printf("o");
		Sleep(150);
		printf(" ");
		Sleep(150);
		printf("w");
		Sleep(150);
		printf("o");
		Sleep(150);
		printf("r");
		Sleep(150);
		printf("l");
		Sleep(150);
		printf("d\n");
		Sleep(150);
		printf("Press any key to start this game_\n");
		Sleep(150);
		printf("Press\n1:Start Game");
		printf("\n2:Setting");
		con = _getch();
		if (con == '1')
		{
			printf("\n");
			goto CARTON;
		}
	}
	CARTON:while (i <= 15)
	{
		i++;
		printf("■");
		Sleep(80);
	}
	printf("\nOVER!");
	Sleep(50);
	i = 0;
	srand((unsigned)time(NULL));
	foeX = rand() % 38 + 1;
	foeY = ((foeX % 3)+1)* 4;
	GAME:while (1)
	{
		system("cls");
		if (x == foeX && y == foeY)
		{
			x = 20;
			y = 10;
			break;
		}
		
		printf("X:%d Y:%d x:%d y:%d 方向状态:%d 输出状态:%d 分数:%d %d\n", x, y, foeX, foeY, where, fire, score,j);
		if (die == 1)
		{
			srand((unsigned)time(NULL));
			foeX = rand() % 38 + 1;
			foeY = ((foeX % 3) + 1) * 4;
			die = 0;
		}
		for (b = 0; b <= 21; b++)
		{
			for (a = 0; a <= 38; a++)
			{
				if (fire == 1 && where == 2 && a == (x - 1) && b < (y - 1))
				{
					printf("○");
				}
				else
				{
					if (fire == 1 && where == 1 && a < (x - 1) && b == (y - 1))
					{
						printf("○");
					}
					else
					{
						if ((x - 1) == a && (y - 1) == b)
				 		{
							printf("♀");
						}
						else
						{
							if (where == 4 && fire == 1 && a > (x - 1) && b == (y - 1))
							{
								printf("○");
							}
							else
							{
								if (fire == 1 && where == 3 && a == (x - 1) && b > (y - 1))
								{
									printf("○");
								}
								else
								{
									if ((foeX - 1) == a && (foeY - 1) == b && die == 0)
									{
										printf("☆");
									}
									else
									{
										if (j == 0)
										{
											printf("  ");
										}
										else
										{
											printf(" .");
										}
									}
								}
							}
						}
					}
				}
			}
			printf("\n");
		}
		fire = 0;
		input = _getch();
		if (input == 'w')
		{
			y--;
			where = 2;
			if (y < 1)
			{
				y = 1;
			}
		}
		else
		{
			if (input == 's')
			{
				y++;
				where = 3;
				if (y > 22)
				{
					y = 22;
				}
			}
			else
			{
				if (input == 'a')
				{
					x--;
					where = 1;
					if (x < 1)
					{
						x = 1;
					}
				}
				else
				{
					if (input == 'd')
					{
						x++;
						where = 4;
						if (x > 39)
						{
							x = 39;
						}
					}
					else
					{
						if (input = ' ')
						{
							fire = 1;
							if (where == 1 && foeX < x && foeY == y)
							{
								die = 1;
								score++;
							}
							else
							{
								if (where == 3 && foeX == x && foeY > y)
								{
									die = 1;
									score++;
								}
								else
								{
									if (where == 2 && foeX == x && foeY < y)
									{
										die = 1;
										score++;
									}
									else
									{
										if (where == 4 && foeX > x && foeY == y)
										{
											die = 1;
											score++;
										}
										else
										{
											if (input == 'f')
											{
												if (j == 0)
												{
													j == 1;
												}
												else
												{
													if (j == 1)
													{
														j = 0;
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	system("cls");
	printf("Game Over!\nPress any key to play again!\n"); 
	system("pause");
	goto GAME;
}